'use strict';

angular.module('snPaas').service('vecProcess',[function(){
	var p = {};
	p.getSelected = function(selList,selId,allList,allId){
		var arr = [];
		for(var i = 0,l = selList.length;i<l;i++){
			var id = selList[i][selId];

			for(var j = 0,ll = allList.length;j<ll;j++){
				if(allList[j][allId] == id){
					allList[j].selected = true;
					allList[j].defaultVal1 = selList[i].defaultVal1;
					allList[j].defaultVal2 = selList[i].defaultVal2;
					allList[j].defaultVal3 = selList[i].defaultVal3;
					allList[j].defaultVal4 = selList[i].defaultVal4;
					allList[j].defaultVal5 = selList[i].defaultVal5;
					selList[i].linked = allList[j];
					break;
				}
			}
		}
		return selList;
	};
	return p;
}])
.service('bitConverter',[function(){
	return function(v){
		var val = parseInt(v);
		if(!val){
			val = 0;
		}
		if(val <1024){
			return val +'MB';
		}
		else{
			val = val/1024;
			return val +'GB';
		}
	};
}])
.service('dateConverter',[function(){
	var toDate = function(ts,isStart){
		var time = '23:59:59';
		if(isStart){
			time = '00:00:00';
		}
		var date = new Date(ts);
		var y =  date.getFullYear(),
		m = date.getMonth()+1,
		d = date.getDate();
		return y+'-' + m +'-' +d+' '+time;
	};


	return {
		toDate : toDate
	};
}])
;